import 'package:flutter_common_utils/common_utils_export.dart';

import '../../generated/json/base/json_convert_content.dart';

//自定义Json 转换
class AppJsonConvert extends JsonConvert {
  static void init() {
    jsonConvert = AppJsonConvert();
  }

  @override
  T? convert<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
    if (value == null) {
      return null;
    }
    if (value is T) {
      return value;
    }
    try {
      String type = T.toString();
      if (type == "num") {
        return num.tryParse(value.toString()) as T?;
      } else {
        return super.convert<T>(value, enumConvert: enumConvert);
      }
    } catch (e, stackTrace) {
      LogUtils.e('convert<$T> $e $stackTrace');
      return null;
    }
  }
}
